package com.bnlr.lrparking.appui.appoint.adapter;

import android.support.annotation.Nullable;
import android.view.View;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.bnlr.lrparking.R;
import com.bnlr.lrparking.appui.appoint.bean.AppointBean;
import com.bnlr.lrparking.view.CarCommon;
import com.bnlr.lrparking.widget.SuperTextView;

import java.util.List;

/**
 * Created by Administrator on 2017/12/16 0016.
 */

public class AppointAdapter  extends BaseQuickAdapter<AppointBean.DataBean,BaseViewHolder>{
    private AppointHandlerListener appointHandlerListener;
    public AppointAdapter(@Nullable List<AppointBean.DataBean> data) {
        super(R.layout.item_appoint_layout,data);
    }

    public void setAppointHandlerListener(AppointHandlerListener appointHandlerListener) {
        this.appointHandlerListener = appointHandlerListener;
    }

    @Override
    protected void convert(final BaseViewHolder helper, final AppointBean.DataBean item) {
        helper.setText(R.id.tv_appoint_title, item.getTimeString());
        ImageView ivPic = helper.getView(R.id.tv_appoint_pic);
        Glide.with(mContext).load(item.getPhotoUrl()).placeholder(R.mipmap.tab2_defaultgraph).error(R.mipmap.tab2_defaultgraph).into(ivPic);
        helper.setText(R.id.tv_appoint_number, item.getNumber());
        helper.setText(R.id.tv_appoint_address,item.getAddress());
        helper.setText(R.id.tv_appoint_floor,item.getFloorNum());
        SuperTextView call = helper.getView(R.id.stv_appoint_call);
        final SuperTextView pay = helper.getView(R.id.stv_appoint_cancel);
        call.setOnTextViewClickListener(new SuperTextView.OnTextViewClickListener() {
            @Override
            public void onClick(View v) {
                CarCommon carCommon = new CarCommon();
                carCommon.phoneDialog(mContext);
            }
        });
        if (item.getDealStatus() == 0) {
            helper.setVisible(R.id.iv_expired,false);
            pay.setVisibility(View.GONE);
        } else {
            helper.setVisible(R.id.iv_expired,true);
            pay.setVisibility(View.VISIBLE);
            pay.setText("删除记录");
        }
        pay.setOnTextViewClickListener(new SuperTextView.OnTextViewClickListener() {
            @Override
            public void onClick(View v) {
                if (appointHandlerListener != null) {
                    appointHandlerListener.onCancel(v,helper.getAdapterPosition(),item,false);
                }
            }
        });
    }
    public interface AppointHandlerListener {
        /**
         *
         * @param view
         * @param position
         * @param item
         * @param isCancel 是否为删除 是否为预约
         */
        void onCancel (View view,int position,AppointBean.DataBean item,boolean isCancel);
    }
}
